package com.opendi.dynamic.conf;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Order(value = -100)
@Slf4j
@Aspect
public class DataSourceSwitchAspect {

    @Pointcut("execution(* com.opendi.dynamic.dao.opdi..*.*(..))")
    private void opdiAspect() {
    }

    @Pointcut("execution(* com.opendi.dynamic.dao.yw..*.*(..))")
//    execution(* com.xyz.service.*.*(..))
//    execution(* com.zwyl.bazhong.dao.mapper.db2..*.*(..))
    private void ywAspect() {
    }


    @Before("opdiAspect()")
    public void opdi() {
        log.info("切换到数据仓库1的数据源了...");
        DbContextHolder.setDbType(DBTypeEnum.opdi);
    }

    @Before("ywAspect()")
    public void yw() {
        log.info("切换到数据仓库2的数据源了...");
        DbContextHolder.setDbType(DBTypeEnum.yw);
    }
}
